﻿/// <summary>
/// data   :2016-05-03
/// author :fanzhengyong
/// 游戏状态：初始化本地资源
/// </summary>
using UnityEngine;
using System.Collections;

namespace UEngine
{
    class GameStateInitLocalRes : GameState
    {
        public GameStateInitLocalRes()
        {
            State = EGameState.InitLocalRes;
        }

        public override void Enter()
        {
            Debug.Log("enter InitLocalRes.");
            Canvas        canvas              = null;
            RectTransform canvasRectTransform = null;
            
            canvas  = GameObject.FindWithTag("UIRoot").GetComponent<Canvas>();
            if (canvas == null)
            {
                return;     
            }

            canvasRectTransform = canvas.gameObject.GetComponent<RectTransform>();
            if (canvasRectTransform == null)
            {
                return;
            }

            GameObject loadingGo = null;
            loadingGo = GameObject.Instantiate(Resources.Load("UI/Image_Loading", 
               typeof(GameObject))) as GameObject;

            if (loadingGo == null)
            {
                DebugHelper.ErrorMessage("loadingGo == null");
            }

            InitLocalResLoadingCom initLoadingCom = loadingGo.GetComponent<InitLocalResLoadingCom>();
            if (initLoadingCom == null)
            {
                initLoadingCom = loadingGo.AddComponent<InitLocalResLoadingCom>();
            }
            loadingGo.SetActive(true);
            loadingGo.transform.SetParent(canvasRectTransform, false);
        }

        public override void Update()
        {

        }

        public override void Exit()
        {
            Debug.Log("exit InitLocalRes.");
        }

    }
}
